﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Web.Http;
using Innovacall.MyPrettyCMS.PlugIns.PI_ContactManager_DataLayer;
using Innovacall.MyPrettyCMS.PlugIns.PI_ContactManager_DomainLayer;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MPC_PI_ContactManager;
using MPC_PI_ContactManager.Controllers.ODataControllers;
using EmitMapper;

namespace MPC_PI_ContactManager.Tests.Controllers.ODataControllers
{
    [TestClass]
    public class ContactsControllerTest
    {
        [TestMethod]
        public void Get()
        {
            #region TestPreparation
            int directEFCount = 0;
            string firstName = string.Empty;
            List<v_Contact> contactOrderedList = null;
            using (DataRepositories _dataContext = new DataRepositories())
            {  
                directEFCount = _dataContext.v_Contact_Rep.GetAll().Count();
                firstName = _dataContext.v_Contact_Rep.GetAll().First().Name;
                contactOrderedList = _dataContext.v_Contact_Rep.GetAll().OrderBy(x => x.PersonType).OrderBy(x => x.Name).ToList();
            }
            #endregion


            ContactsController controller = new ContactsController();
            IQueryable<v_Contact> result = controller.Get();
            Assert.IsNotNull(result);
            Assert.AreEqual(directEFCount, result.Count());
            Assert.AreEqual(firstName, result.First().Name);
        }

        [TestMethod]
        public void GetById()
        {
            #region TestPreparation
            v_Contact dbContact = null;
            using (DataRepositories _dataContext = new DataRepositories())
            {
                dbContact = _dataContext.v_Contact_Rep.GetById(1);
            }
            #endregion

            ContactsController controller = new ContactsController();
            v_Contact contact = controller.GetByKey(1);
            Assert.AreEqual(dbContact.Id, contact.Id);
            Assert.AreEqual(dbContact.Name, contact.Name);
            Assert.AreEqual(dbContact.PersonType, contact.PersonType);
        }

        [TestMethod]
        public void Post()
        {
        }

        [TestMethod]
        public void Put()
        {
        }

        [TestMethod]
        public void Delete()
        {
        }
    }
}
